<template>
  <div
    class="double-fence"
    :class="customClass"
  >
    <div
      class="double-fence-cell"
      v-for="(item,index) in items"
      :key="index"
    >
      <van-cell
        :title="item.title"
        :label="item.description"
        center
        :border="false"
      >
        <image
          :src="item.thumb"
          :style="iconStyle"
          mode="aspectFit"
        />
      </van-cell>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DoubleFence',
  props: {
    items: {
      type: Array,
      default: []
    },
    customClass: String,
    iconWidth: [Number, String],
    iconHeight: [Number, String]
  },
  computed: {
    iconStyle () {
      let style = []
      if (this.iconWidth) {
        let width = this.addUnit(this.iconWidth)
        style.push(`width:${width}`)
      }
      if (this.iconHeight) {
        let height = this.addUnit(this.iconHeight)
        style.push(`height:${height}`)
      }

      return style.join(';')
    }
  },
  methods: {
    addUnit (value) {
      if (value) {
        return /^\d+(\.\d+)?$/.test(value) ? value + 'px' : value
      }
      return undefined
    }
  }
}
</script>

<style lang="less" scoped>
.double-fence {
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-wrap: wrap;
  &-cell {
    flex-basis: 50%;
    /deep/ .van-cell {
      padding: 10px;
      &__value {
        flex: none;
        -webkit-flex: none;
        display: flex;
        align-items: center;
      }
      image {
        width: 30px;
        height: 30px;
      }
    }
  }
}
</style>
